package com.example.hotdeploy.controller;

import com.example.hotdeploy.hot.HotDeployFactory;
import com.example.hotdeploy.service.FeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @Description:
 * @Author: kai.yang
 * @Date: 2019-03-10 07:06
 */
@Controller
@RequestMapping("/api")
public class BillController {

    @Autowired
    FeeService feeService;

    @RequestMapping("/fee/{amount}/{feerate}")
    @ResponseBody
    public String test(@PathVariable String amount, @PathVariable String feerate) {
        try {
            return feeService.callUserFee(new BigDecimal(amount), feerate);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "fail";
    }

    @RequestMapping("/up")
    @ResponseBody
    public String upgrade() {
        HotDeployFactory.upgrade();
        return "ok";
    }
}
